<template>
  <view class="flex flex-direction margin-xs">

    <view class="page-container" v-if="flights_result && flights_result.dataList">
      <buk-flight-card v-for="(item, index) in flights_result.dataList" :key="index"
        :flightInfo="item"></buk-flight-card>
    </view>


  </view>
</template>

<script setup>
  import {
    ref,
    reactive
  } from 'vue'
  import {
    onShow,
    onLoad
  } from '@dcloudio/uni-app'
  import {
    useFlightStore
  } from '@/store/flight.js'
  import {
    rav
  } from '@/common/api/flight.js'
  import rav_result from '@/tests/data/rav_result.json'

  const flightStore = useFlightStore()

  const searchParams = reactive({
    dcity_code: '',
    dcity_name: '',
    acity_code: '',
    acity_name: '',
    ddate: '',
    route_type: 0,
    airline_code: 'CZ'
  })
  const flights_result = ref(null)


  onLoad(() => {
    if (flightStore.dcity_code === '') {
      flightStore.setSearchParams({
        dcity_code: searchParams.dcity_code,
        dcity_name: searchParams.dcity_name,
        acity_code: searchParams.acity_code,
        acity_name: searchParams.acity_name,
        ddate: searchParams.ddate,
        route_type: searchParams.route_type,
        airline_code: searchParams.airline_code
      })
    }

    searchFlights();
  })


  function searchFlights() {
    const params = {
      "dcity": searchParams.dcity_code,
      "acity": searchParams.acity_code,
      "ddate": searchParams.ddate,
      "routeType": searchParams.route_type,
      "carrier": searchParams.airline_code
    };


    flights_result.value = rav_result

    console.log(flights_result.value)

    try {
      // loading.value = true
      // uni.showLoading({
      // 	title: "查询中......"
      // })
      // rav(
      // 	params,
      // 	(v) => {
      // 		// console.log(v)
      // 		hotels.value = v.hotels;
      // 		pageNo.value = v.pageNo
      // 		pageTotal.value = v.pageTotal
      // 		rowCount.value = v.rowCount
      // 		// console.log(hotels)
      // 		// console.log(hotels.value)
      // 	},
      //      (err) => {
      //        console.error(err)
      //      }
      // 	() => {
      // 		loading.value = false
      // 		uni.hideLoading()
      // 	}
      // );
    } catch (err) {
      console.log(err)
    }
  }

  function viewHotelDetails(hotelInfo) {
    // console.log(type)
    // console.log(hotelInfo)
    hotelStore.updateHotelInfo(hotelInfo)
    uni.navigateTo({
      url: `/pages/hotel/HotelDetails`
    });
  }

  function changePage(e) {
    pageNo.value = e.current
    searchHotels2()
  }
</script>

<style>
  .page-container {
    padding-left: 5px;
    padding-right: 5px;
    -webkit-box-sizing: border-box;
    box-sizing: border-box;
    border: 2px dodgerblue dotted;
  }

  .right-align {
    display: flex;
    justify-content: flex-end;
    /* 水平靠右 */
    align-items: center;
    /* 垂直居中（可选） */
  }
</style>